이더넷 모듈을 구매했고, 온습도 센서로 측정한 측정값을 이더넷 모듈에 지정해준 고정IP에 접속해서 계속해서 확인하는 코드를 짜고있습니다.
상품 페이지에 올려주신 이 코드에서
#include <EtherCard.h>
//0은 DHCP, 1은 Static으로 설정
#define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below)
//Static IP 일 경우 설정
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,6 };
// gateway ip address
static byte gwip[] = { 192,168,0,204 };
#endif
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
//요청이 왔을 경우 뿌려줄 HTML 소스
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"Ethernet Module Test_EDUINO"
"</title></head>"
"<body>"
"<h3>Eduino Ethernet Module Test</h3>"
"<p><em>"
"Let's Play With Arduino<br />"
"</em></p>"
"</body>"
"</html>"
;
void setup(){
Serial.begin(57600);
Serial.println("\n[backSoon]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
#define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below)
void loop(){
//웹브라우저의 요청이 들어왔을 경우 page 의 내용을 보내줌
// wait for an incoming TCP packet, but ignore its contents
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
}
저는 고정IP를 사용할거니까 STATIC 1로 모두 설정해주었고 그 이후가 의문인데
제가 이더넷 없이 온습도 센서만 가지고 테스트 했을때는 온도와 습도 변수를 loop() 안에 넣어서 측정을 했었는데... 저 HTML코드는 아예 메소드 밖에 있고...
이 값을 어떻게 웹페이지에 뜰 수 있게 할 수 있을까요? 혹시 소스코드가 있으시다면 보내주실 수 있을까요?
참고해보세요
앞에 코드를 입력하니까 자꾸 'Ethernet' is not a class, namespace, or enumeration 라는 에러가 뜹니다. 근데 제가 본문에 쓴 코드를 쓰면 또 에러가 안나요..